<?PHP
$PurviewLevel=0;
require("../../inc/common.inc.php");
require_once(dirname(__FILE__)."/../"."Admin_ChkPurview.php");
if(intval($pagetype)==0){$pagetype=2;}
$poststr = "&type=".$type."&pagetype=".$pagetype."&keyword=".$keyword."$mtype=".$mtype;
$poststr2 = "&type=".$type."&keyword=".$keyword."$mtype=".$mtype;
$poststr3 = "&type=".$type."&keyword=".$keyword;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<TITLE>铭讯EOS网站后台管理</TITLE>
<Meta name="Keywords" Content="济南网站建设 济南网站制作 山东网站建设 济南铭讯软件有限公司">
<Meta name="Description" Content="济南网站制作：铭讯软件专业服务优秀企业，致力于网站建、设网站推广、网络营销一体的全访位网络服务商">
<link href="../images/style.css" rel="stylesheet" type="text/css" />
</head>

<body>
<?php require("../mx_head.php") ;
if ($action=="work"){
    //设置推荐
	if(!$listdb&&!$id){
		$fun->popmassage("请选择一条信息","","popback");
		exit();
	}
	elseif(is_array($listdb))
	{
		foreach($listdb AS $key=>$value){
			$replyinfo = $db->excu("select * from mx_tuisong_reply where rsucaiid='".$key."'");
			$menuinfo = $db->excu("select * from mx_weixin_menu where mtsucaiid='".$key."'");
			if($db->num_rows($replyinfo)==0 and $db->num_rows($menuinfo)==0){
				$msginfo=$db->get_one("SELECT * FROM mx_sucai_msg WHERE mid='$key' and fid=0");
				if($msginfo){
					if($msginfo["mtype"]==1){
						$sonmsgquery = $db->excu("select * from mx_sucai_msg where fid='$key' and mtype=1");
						while($sonmsgarr = $db->fetch_array($sonmsgquery)){
							dowork($sonmsgarr["mid"],$jobs);
						}
					}
				}
				dowork($key,$jobs);
			}
		}
	}elseif($id){
		$replyinfo = $db->excu("select * from mx_tuisong_reply where rsucaiid='".$id."'");
		$menuinfo = $db->excu("select * from mx_weixin_menu where mtsucaiid='".$id."'");
		if($db->num_rows($replyinfo)==0 and $db->num_rows($menuinfo)==0){
			$msginfo=$db->get_one("SELECT * FROM mx_sucai_msg WHERE mid='$id' and fid=0");
			if($msginfo){
				if($msginfo["mtype"]==1){
					$sonmsgquery = $db->excu("select * from mx_sucai_msg where fid='$id' and mtype=1");
					while($sonmsgarr = $db->fetch_array($sonmsgquery)){
						dowork($sonmsgarr["mid"],$jobs);
					}
				}
			}
			dowork($id,$jobs);
		}else{
			$fun->popmassage("该素材正在使用中不可删除","","popback");
			exit();
		}
	}
$url=$fromurl?$fromurl:$FROMURL;
	jump2("操作成功，已自动过滤使用中的素材",$url,1);

}

function dowork($id,$job){
	global $db,$pre,$timestamp,$userdb,$webdb,$fiddbadmin,$Purview,$fun,$OtherPurview,$Purview,$usersql;
	$rsdb=$db->get_one("SELECT * FROM mx_sucai_msg WHERE mid='$id'");
	if($job=="delete")
	{
	    if (strpos("****".$OtherPurview,'shenhe')<=0 and $Purview!=1 and $Purview!=3){
		    $fun->popmassage("您没有此项管理权限","","popback");
		    exit();
		}
		$pic=$db->get_one("select * from mx_sucai_file WHERE fid='$rsdb[mpic]'");
		if ($pic){@unlink("../..".$pic["fpath"]);}
		//删除附件
		$db->excu("DELETE FROM mx_sucai_file WHERE fid='".$rsdb[mpic]."'");
		$db->excu("DELETE FROM mx_sucai_msg WHERE mid='$id'");
	}
}
?>
	<div class="right">
	  <div class="gk">
			<div class="ti1 fl">图文消息</div>
			<ul class="fr">
				<li><span class="c1"><?php echo $db->num_rows($db->excu("select mid from mx_sucai_msg where fid=0"));?></span><span>信息总条数</span></li>
				<li class="line"></li>
				<li><span class="c2"><?php echo $db->num_rows($db->excu("select mid from mx_sucai_msg where fid=0 and isok=0"));?></span><span>未审核条数</span></li>
				<li class="line"></li>
				<li><span class="c3"><?php echo $db->num_rows($db->excu("select mid from mx_sucai_msg where fid=0 and isok=1"));?></span><span>已审核条数</span></li>
			</ul>
			<div class="clear"></div>
	  </div>
		<div class="height15"></div>
		<div class="xm2">
			<h1 class="fl">信息列表</h1>
			<!--<span class="fr"><a href="#"><img src="../images/right_4.png" alt="设置" /></a></span>-->
		</div>
        
		<div class="xm2_b">
        	<div class="t">
				<div><input type="button" <?php echo $mtype==""?'class="button"':'class="button2"';?> value="图文信息" onclick="window.location='sucai_text.php?1=1<?php echo $poststr3;?>'">&nbsp;<input type="button" <?php echo $mtype==""?'class="button2"':($mtype==1?'class="button2"':'class="button"');?> value="单图文" onclick="window.location='sucai_text.php?mtype=0<?php echo $poststr3;?>'">&nbsp;<input type="button" <?php echo $mtype==""?'class="button2"':($mtype==1?'class="button"':'class="button2"');?> value="多图文" onclick="window.location='sucai_text.php?mtype=1<?php echo $poststr3;?>'">&nbsp;<input type="button" class="button2" value="添加单图文" onclick="window.location='sucai_text_add.php'">&nbsp;<input type="button" class="button2" value="添加多图文" onclick="window.location='sucai_text_adds.php'"></div>
				<div class="clear"></div>
			</div>
			<div class="t">
				<div class="l1 fl"><select onChange="javascript:window.location=this.value;"><option value="sucai_text.php?pagetype=1<?php echo $poststr2;?>" <?php echo $pagetype==1?'selected="selected"':'';?>>12</option><option value="sucai_text.php?pagetype=2<?php echo $poststr2;?>" <?php echo $pagetype==2?'selected="selected"':'';?>>6</option></select></div>
				<div class="l2 fl">选择每页的信息数量，默认值为：6条/页。</div>
				<div class="l3 fr"><div class="l">快速检索: </div><div class="r"><input name="keyword" type="text" value="<?php echo $keyword;?>" onkeydown="setTrack(this,event)" /></div></div>
				<div class="clear"></div>
			</div>
			<div class="height15"></div>
				<script type="text/javascript" src="../js/jquerys-1.5.1.js"></script>
                
				<script language="javascript">
				
				function setTrack(tt,event){
				var e = event?event:window.event
				if(e.keyCode == 13){
				window.location="sucai_text.php?type=title&pagetype=<?php echo $pagetype;?>&keyword="+tt.value;
				}
				}
				</script>
                <script language="javascript">
				function postdo(va){
					if (va=="delete"){
						if(!confirm("您确认要删除这些记录吗?")){
						return false;
						}
					}
					document.form1.jobs.value=va
					document.form1.submit();
				}
				
				function CheckAll(va,zt){
					form=document.form1
					for (var i=0;i<form.elements.length;i++){
						var e = form.elements[i];
						if(va=='all'){
							e.checked = zt;
						}else{
							e.checked == true ? e.checked = false : e.checked = true;
						}
					}
				}
				function subform(){
						 if(document.all.type.value==""){
							alert("请选择查询条件！");
							return false;
						 }
						document.form2.submit();
				}
				var html = new Array();　
				</script>
                
                <form name="form1" action="sucai_text.php?action=work<?php echo $poststr;?>" method="post">
			<div class="imglist11">
            	 <?php
			  if(empty($pageindex)){$pageindex=1;}
			  $str=" and fid=0 ";
			  if($mtype!=""){
				  $str.=" and mtype=$mtype ";
			  }
			  if($type=="yz"){
				  $str.=" AND isok=1 ";
			  }
			  elseif($type=="unyz"){
				  $str.=" AND isok=0 ";
			  }
			  elseif($type=="title"){
				  $str.=" AND mtitle LIKE '%$keyword%' ";
			  }
			  $order="order by addtime desc, mid desc";
			  $pagesize = $pagetype==1?"12":"6";
			  $table=" mx_sucai_msg ";
			  $column=" * ";
			  $c=$db->listcount($table,$str);
			  $list=$db->list1($pageindex,$pagesize,$table,$column,$str,$order);
			  if(!is_array($list) or $c==0){
				echo '<table width="100%" border="0" align="center" cellpadding="9" cellspacing="1" bgcolor="#CCCCCC" class="stripe"><tr><td colspan="10"><p style="height:30px;text-align:center;line-height:30px;">暂无信息</p></td></tr></table>';
			  }
			  else{
			  for($i=0;$i<count($list);$i++){
				  $mtypestr="";
				  if($list[$i]["fid"]==0&&$list[$i]["mtype"]==1){$mtypestr='&nbsp;&nbsp;<a href="sucai_text_adds.php?fid='.$list[$i]["mid"].'">增加一条</a>';}
				  //获得封面图片
				  $mpic = $db->getinfo("select fpath from mx_sucai_file where fid = ".$list[$i]["mpic"]." limit 1");
				  //获得多图文的下属图文消息、
				  $smsg = array();
				  if($list[$i]["mtype"]==1){
					  $smsgquery = $db->excu("select * from mx_sucai_msg where fid=".$list[$i]["mid"]." order by addtime,mid");
					  
					  while($smsgarr = $db->fetch_array($smsgquery)){
						  $smsg[] = $smsgarr;
					  }
				  }
				  
			  ?>
              <script language="javascript">
			  var showcon = '<iframe src="get_mobileshow.php?id=<?php echo $list[$i]["mid"];?>&type=msg" class="showbox" id="showpiciframe" frameborder="0"></iframe>';
			  html.push(showcon);
              </script>
                <div class="imgitem">
                	<div class="imgitemtop"></div>
                    <div class="imgitembod">
                    	<div class="imgitembod-img"><a href="sucai_text_edit.php?id=<?php echo $list[$i]["mid"];?>"><img src="<?php echo get_photourl($mpic["fpath"])?>" width="300" height="211" /></a></div>
                        <div class="imgitembod-txt">
                            <h1><a href="sucai_text_edit.php?id=<?php echo $list[$i]["mid"];?>"><?php echo wordscut($list[$i]["mtitle"],50,"...")?></a></h1>
                            <span><?php echo date("Y/m/d",$list[$i]["addtime"])?></span>
                        </div>
                        <div class="imgitembod-act">
                        	<div class="act-r"><a href="sucai_text.php?action=work&jobs=delete&id=<?php echo $list[$i]["mid"]?><?php echo $poststr;?>" onClick="return confirm('删除后不可恢复,你确实要删除吗?')"><img src="../images/imgsc.gif" width="11" height="11" /> 删除</a></div>
                            <div class="act-l"><a href="sucai_text_edit.php?id=<?php echo $list[$i]["mid"];?>"><img src="../images/imgbj.gif" width="11" height="11" /> 编辑</a></div>
                            <div class="act-l"><a href="javascript:void(0)" onclick='showBox(200,265,"<?php echo $i;?>");'><img src="../images/imgyl.gif" width="11" height="11" /> 预览</a></div>
                            <div class="act-l"><?php 
							switch($list[$i]["mtype"]){
								case 0;echo"单图文";break;
								case 1;echo"多图文(".count($smsg).")";break;
							}
							?></div>
                            <?php
                            if($list[$i]["mtype"]==1){
								echo'<div class="act-l"><a href="sucai_text_adds.php?fid='.$list[$i]["mid"].'">增加一条</a></div>';
							}
							?>
                        </div>
                    </div>
                    <div class="imgitembot"></div>
                </div>
                <?php
			  }
			  }
			  ?>
                <div class="clear"></div>
            </div>
            </form>
			<script type="text/javascript" src="../js/lightBox.js"></script>
				<script>
				function showBox(conwidth,conheight,showid){
					showcon = html[showid];
					Box("mobile",conwidth,conheight,showcon,"");
				}
				</script>
			<div class="height15"></div>
			<div class="pagination">
				<?php if ($c>$pagesize){echo $db->ThePage_mxsoft($s,$pageindex,$c,$pagesize,'','',0,4,''.$poststr.'');}?>
			</div>
            <div class="clear"></div>
			<div class="height15"></div>
		</div>
        
		<div class="clear"></div>
   <?php require("../mx_foot.php") ;?>
  </div>
</body>
</html>